package com.atguigu.srb.oss.controller;

import com.atguigu.common.results.R;
import com.atguigu.srb.oss.service.OssService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin/oss")
public class OssController {
    @Autowired
    OssService ossService;
    //上传文件
    @ApiOperation("上传文件")
    @PostMapping("upload")
    public R upload(MultipartFile file){
        String imgPath = ossService.upload(file);
        return R.success().data("path" , imgPath);
    }
    @ApiOperation("删除文件")
    @DeleteMapping("delete")
    public R delete(String imgPath){
        ossService.delete(imgPath);
        return R.success().message("文件删除成功");
    }
}
